home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBCharsAvailable.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  1.9 KB  |  76 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBCharsAvailable() -- Return the number of characters immediately available for reading.
  3.  
  4.     To compile and link this file using Macintosh Programmer's Workshop,
  5.  
  6.         pascal -w CTBCharsAvailable.p
  7.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=2751 -sn Main=CTBCharsAvailable ∂
  8.             CTBCharsAvailable.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  9.  
  10.     © Copyright 1990 by Apple Computer, Inc.
  11.  
  12.     Initial coding 2/90 by Harry R. Chesley.
  13. *)
  14.  
  15. {$R-}
  16.  
  17. {$S CTBCharsAvailable }     { Segment name must be the same as the command name. }
  18.  
  19. unit DummyUnit;
  20.  
  21. interface
  22.  
  23. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  24.  
  25. procedure EntryPoint(paramPtr: XCmdPtr);
  26.     
  27. implementation
  28.  
  29. procedure CTBCharsAvailable(paramPtr: XCmdPtr); forward;
  30.  
  31. procedure EntryPoint(paramPtr: XCmdPtr);
  32.  
  33.     begin
  34.         CTBCharsAvailable(paramPtr);
  35.     end;
  36.  
  37. procedure CTBCharsAvailable(paramPtr: XCmdPtr);
  38.  
  39.     {$I CTBUtil.inc}
  40.  
  41.     var l: longInt;
  42.         sizes: CMBufferSizes;
  43.         status: CMStatFlags;
  44.         s: Str255;
  45.         theBuf: InputBufferHandle;
  46.  
  47.     procedure Fail(errMsg: Str255); { set theResult and quit }
  48.         begin
  49.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  50.             exit(CTBCharsAvailable);
  51.         end;
  52.  
  53.     begin
  54.         { Check the parameter count. }
  55.         if paramPtr^.paramCount <> 0 then Fail('Invalid parameter count');
  56.  
  57.         { Make sure the Comm Toolbox is willing. }
  58.         CTBReady;
  59.         { And the connection tool's here. }
  60.         EnsurePresent(connectionTool);
  61.         { And it's open. }
  62.         EnsureOpen;
  63.  
  64.         { Get the input buffer. }
  65.         theBuf := InputBufferHandle(CMGetUserData(Globals^^.connHand));
  66.         { Find out how many bytes are available. }
  67.         if CMStatus(Globals^^.connHand,sizes,status) = noErr then
  68.             l := sizes[cmDataIn] + theBuf^^.amountLeft
  69.         else l := theBuf^^.amountLeft;
  70.         { Convert it to a string and return it. }
  71.         LongToStr(paramPtr,l,s);
  72.         paramPtr^.returnValue := PasToZero(paramPtr,s);
  73.     end;
  74.  
  75. end.
  76.